<script>
	export default {
		onLaunch: function() {
			uni.getLocation({
				type: 'wgs84',
				geocode: true, //设置该参数为true可直接获取经纬度及城市信息
				success: function(res) {
					console.log(res)
     
				},
				fail: function(res) {
					uni.showToast({
						title: '获取地址失败，将导致部分功能不可用',
						icon: 'none'
					});
				}
			});
		},
		onShow: function() {
			var that = this;
			var token = that.$store.state.vuex_token
			if (token != undefined && token != "") {
				setInterval(function() {
					uni.getLocation({
						type: 'wgs84',
						geocode: true, //设置该参数为true可直接获取经纬度及城市信息
						success: function(res) {
							//提交到后台
							let parme = {
								"longitude": res.longitude,
								"latitude": res.latitude,
								"address": res.address.province + res.address.city + res.address.district + res.address.street + res.address
									.streetNum + res.address.poiName
							}
							// console.log(parme)
							that.$u.api.trackSign(parme)
								.then(res => {
									// console.log(res)
								})
								.catch(err => {
									console.log(err)
								})
							},
							fail: function(res) {
								uni.showToast({
									title: '获取地址失败，将导致部分功能不可用',
									icon: 'none'
								});
							}
						});
					}, 120000);
				}

			},
		onHide: function() {
			var that = this;
			var token = that.$store.state.vuex_token
			if (token != undefined && token != "") {
				setInterval(function() {
					uni.getLocation({
						type: 'wgs84',
						geocode: true, //设置该参数为true可直接获取经纬度及城市信息
						success: function(res) {
							//提交到后台
							let parme = {
								"longitude": res.longitude,
								"latitude": res.latitude,
								"address": res.address.province + res.address.city + res.address.district + res.address.street + res.address
									.streetNum + res.address.poiName
							}
							that.$u.api.trackSign(parme).then(res => {

								// console.log(res)
							}).catch(err => {
								console.log(err)
							})
						},
						fail: function(res) {
							console.log(res)
							uni.showToast({
								title: '获取地址失败，将导致部分功能不可用',
								icon: 'none'
							});
						}
					});
				}, 120000);
			}
		},
	}
</script>

<style lang="scss">
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */

	view,
	image {
		margin: 0;
		padding: 0;
		box-sizing: border-box;
	}

	image {
		width: 100%;
		height: 100%;
	}
</style>
